package tx.bj12320.service;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.*;

import javacommon.base.*;
import javacommon.util.*;

import cn.org.rapid_framework.util.*;
import cn.org.rapid_framework.web.util.*;
import cn.org.rapid_framework.page.*;
import cn.org.rapid_framework.page.impl.*;

import tx.bj12320.model.*;
import tx.bj12320.dao.*;
import tx.bj12320.service.*;
import tx.bj12320.vo.query.*;

@Service
@Transactional
public class DataDictManager extends BaseManager<DataDict,Long>{

	private DataDictDao dataDictDao;
	/**增加setXXXX()方法,spring就可以通过autowire自动设置对象属性,请注意大小写*/
	public void setDataDictDao(DataDictDao dao) {
		this.dataDictDao = dao;
	}
	public EntityDao getEntityDao() {
		return this.dataDictDao;
	}

	@Transactional(readOnly=true)
	public Page findPage(DataDictQuery query) {
		return dataDictDao.findPage(query);
	}
	@Transactional(readOnly=true)
	public List<DataDict> findAllByDdType(String ddType) {
		return dataDictDao.findAllBy("ddType", ddType);
	}


	@Transactional(readOnly=true)
	public List<DataDict> tree(DataDict rootDd) {
		List<DataDict> nodes=dataDictDao.findAllBy("ddParentId", rootDd.getDdId());
		if(nodes.size()==0) return new ArrayList<DataDict>() ;
		for (DataDict dataDict : nodes) {
			List<DataDict> dds=tree(dataDict);
			if(dds.size()!=0) dataDict.setChildren(dds);
		}
		return nodes;
	}

}
